package com.aistar.mapper;

import com.aistar.model.dto.job.RecruitmentAndCompanyDTO;
import com.aistar.model.entity.Intern;
import com.aistar.model.entity.Recruitment;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface RecruitmentMapper {
    //获取全部职位信息
    @Select("select * from recruitment where status=1")
    List<Recruitment> find();

    @Select("select * from recruitment where id=#{id} and status=1")
    Recruitment findById(Integer id);

    //根据id获取职位名称
    @Select("select name from recruitment where id=#{id} and status=1")
    String findByName(Integer id);

    //显示数据库10条数据,upper代表行数,显示行数需要+1,limit代表显示几条
    @Select("select * from recruitment limit #{upper},#{limit} and status=1")
    List<Recruitment> topTitle(int upper, int limit);

    //查找名称
//    @Select("select * from recruitment where name like concat('%',#{name},'%')")
    List<Recruitment> getAll(@Param("name") String name, @Param("experience") String experience, @Param("education") String education,@Param("salaryLower") Integer salaryLower,@Param("salaryUpper")Integer salaryUpper);

    //查找公司名称
//    @Select("select company.name from recruitment join company on recruitment.company_id=comapny.id ")
//    List<RecruitmentAndCompanyDTO> findCompany();

    //根据公司id获取职位
    @Select("select * from recruitment where company_id=#{companyId} and status=1")
    List<Recruitment> findByCompanyId(Integer companyId);

    //根据公司id获取职位
    @Select("select * from recruitment where company_id=#{companyId} and status=1 limit #{pageNow},#{pageSize}")
    List<Recruitment> findByCompanyIdAndPage(@Param("companyId") Integer companyId, @Param("pageNow") Integer pageNow, @Param("pageSize") Integer pageSize);

    //根据id修改职位信息
    @Update("update recruitment set name=#{name},duty=#{duty},requirement=#{requirement},welfare=#{welfare},salary_upper=#{salaryUpper},salary_lower=#{salaryLower},education=#{education},experience=#{experience},contact_name=#{contactName},contact_phone=#{contactPhone},email=#{email},release_time=#{releaseTime},frequency=#{frequency},company_id=#{companyId},status=#{status} where id = #{id} and status=1")
    int updateRecruitment(Recruitment recruitment);

    // 根据id刷新职位发布时间
    @Update("update recruitment set release_time = #{releaseTime} where id = #{id} and status=1")
    int updateRecruitmentTimeById(@Param("id") Integer id, @Param("releaseTime") Date releaseTime);

    // 插入职位信息
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into recruitment(name,duty,requirement,welfare,salary_upper,salary_lower,education,experience,contact_name,contact_phone,email,release_time,frequency,company_id,status) values(#{name},#{duty},#{requirement},#{welfare},#{salaryUpper},#{salaryLower},#{education},#{experience},#{contactName},#{contactPhone},#{email},#{releaseTime},#{frequency},#{companyId},#{status})")
    int insertRecruitment(Recruitment recruitment);

    // 逻辑删除职位信息
    @Update("update recruitment set status=0 where id = #{id} ")
    int delRecruitmentById(Integer id);

    //获取职位福利信息通过id
    @Select("select welfare from recruitment where id=#{id} and status=1")
    String getWelfare(Integer id);

    //根据公司id查找招聘者人数
    @Select("select count(distinct contact_name) from recruitment where company_id=#{id} and status=1")
    int findCount(Integer id);

    //根据经历获取职位
    @Select("select * from recruitment where experience='#{experience}' and status=1")
    List<Recruitment> findExperience(String experience);

    //根据职位id更改查看次数
    @Update("update recruitment set frequency=frequency+1 where id=#{id} and status=1")
    int findFrequency(Integer id);

    // 根据招聘者id获取该招聘者屏蔽的求职者
    @Select("select employee_id from employer_blacklist where employer_id=#{id}")
    List<Integer> findByEmployer(Integer id);

    //根据职位id获取邮箱
    @Select("select email from recruitment where id=#{id} and status=1")
    String findByRId(Integer id);

    //根据职位id获取薪水上限
    @Select("select salary_upper from recruitment where id=#{id}")
    Integer findSalary(Integer id);

    //根据职位id获取薪水下限
    @Select("select salary_lower from recruitment where id=#{id}")
    Integer findSalaryLower(Integer id);

    //查找所有大于下限的钱
    @Select("select * from recruitment where salary_lower<salary")
    List<Integer> findAllLower(Integer salary);

    //根据薪水查找数据
    @Select("select * from recruitment where salary_lower=#{salaryLower} and salary_upper=#{salaryUpper}")
    List<Recruitment> findBySalary(Integer salaryLower,Integer salaryUpper);



}
